/**
 * Created by LC on 2019/11/21
 */
package com.hw.paltfrom.service.mainscreen;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.hw.paltfrom.mapper.HwDataOverrunstationMapper;
import com.hw.paltfrom.pojo.HwDataOverrunstation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class WeightingService {
    @Autowired
    private HwDataOverrunstationMapper hwDataOverrunstationMapper;

    /**
     * 5分钟以内的动态检测总数,未超限检测总数
     * @return
     */
    public Map<String, Object> getTestingNum() {
        //创建5分组之前的时间
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.MINUTE,-5);
        Date startTime = cal.getTime();
        //条件,动态检测总数,前5分钟
        Wrapper<HwDataOverrunstation> overrunstationWrapper = new EntityWrapper<>();
        overrunstationWrapper.between("D_JCSJ",startTime,new Date());
        Integer movingNum = hwDataOverrunstationMapper.selectCount(overrunstationWrapper);
        //条件,未超限检测总数,前5分钟
        overrunstationWrapper.eq("J_SFCZ",0);
        Integer notOverNum = hwDataOverrunstationMapper.selectCount(overrunstationWrapper);
        Map<String,Object> map = new HashMap<>();
        map.put("movingNum",movingNum);
        map.put("notOverNum",notOverNum);

        return map;
    }
    /**
     *  一小时内每5分钟以内的动态检测总数,未超限检测总数
     * @return
     */
    public List<Map<String, Object>> getTestingNumIn5m() {
        List<Map<String,Object>> resultList = new ArrayList<>();
        for (int i = 12; i > 0; i--) {
            Calendar cal = Calendar.getInstance();
            cal.add(Calendar.MINUTE,-5 * i);
            Date startTime = cal.getTime();
            //条件,动态检测总数,前5分钟
            Wrapper<HwDataOverrunstation> overrunstationWrapper = new EntityWrapper<>();
            overrunstationWrapper.between("D_JCSJ",startTime,new Date());
            Integer movingNum = hwDataOverrunstationMapper.selectCount(overrunstationWrapper);
            //条件,未超限检测总数,前5分钟
            overrunstationWrapper.eq("J_SFCZ",0);
            Integer notOverNum = hwDataOverrunstationMapper.selectCount(overrunstationWrapper);
            Map<String,Object> map = new HashMap<>();
            map.put("movingNum",movingNum);
            map.put("notOverNum",notOverNum);
            resultList.add(map);
        }
        return resultList;
    }
}
